package educar.controllers;

import educar.gui.AdminView;
import educar.gui.AlumnoView;
import educar.gui.DocenteView;
import educar.gui.IView;
import educar.gui.LoginView;
import educar.gui.newAlumnoView;
import educar.models.Session;
import educar.models.User;

public class LoginController implements IController
{
    private LoginView view;

    public void processItemList(String name, String item)
    {
    }

    public void process(String model)
    {

        if (null != view)
        {
            view.close();
            if (User.authenticate(view.getUsername(), view.getPassword()))
            {
                if (Session.getCurrentUser().getRole().compareTo("Admin") == 0)
                    new AdminView();
                else if (Session.getCurrentUser().getRole().compareTo("Docente") == 0)
                    new DocenteView();
                else if (Session.getCurrentUser().getRole().compareTo("Alumno") == 0)
                    new newAlumnoView();
            }
            else
            {
                view.present("Wrong username/password");
            }
        }
    }

    @Override
    public void setView(IView view)
    {
        this.view = (LoginView) view;
    }
}
